# -*- coding: utf-8 -*-
import time
import gevent
from multiprocessing import Process as pro
from multiprocessing.dummy import Process as thr
from gevent import monkey; monkey.patch_all()


def run(i):
    lists = range(i)
    sum = 0
    for i in lists:
        sum += i


if __name__ == '__main__':
    concurrence = 100
    num = 500000
    t1 = time.time()
    for i in range(concurrence):
        t = pro(target=run, args=(num, ))
        t.start()
    t2 = time.time()
    print 'process %s' % (t2 - t1)
    for i in range(concurrence):
        t = thr(target=run, args=(num, ))
        t.start()
    t3 = time.time()
    jobs = [gevent.spawn(run, num) for i in range(concurrence)]
    gevent.joinall(jobs)
    for i in jobs:
        i.join()
    t4 = time.time()
    print 'gevent %s' % (t4 - t3)
    for i in range(concurrence):
        run(num)
    t5 = time.time()
    print 'single %s' % (t5 - t4)
